package jys.test.yddata.ui;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.Nullable;
import androidx.appcompat.widget.Toolbar;

import jys.test.yddata.R;

public class ToolbarPlus extends Toolbar {
    // ICON 来自 https://www.iconfont.cn/collections/detail?spm=a313x.7781069.1998910419.d9df05512&cid=38600

    private final static int leftBt = R.id.title_leftbt,
                             textTtl = R.id.title_text,
                             rightBt = R.id.title_rightbt;

    public ToolbarPlus(Context context) {
        super(context);
    }

    public ToolbarPlus(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public ToolbarPlus(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    public ToolbarPlus settingLeft(int imgID, OnClickListener action) {
        ImageView leftView = findViewById(leftBt);
        leftView.setImageResource(imgID);
        leftView.setOnClickListener(action);
        return this;
    }

    public ToolbarPlus settingTitle(String title) {
        TextView textView = findViewById(textTtl);
        textView.setText(title);
        return this;
    }

    public ToolbarPlus settingRight(int imgID, OnClickListener action) {
        ImageView rightView = findViewById(rightBt);
        rightView.setImageResource(imgID);
        rightView.setOnClickListener(action);
        return this;
    }
}
